package com.xiaoyu.client.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.xiaoyu.client.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 图片列表适配器
 * Created by jk on 2018/10/11.
 */
public class ImageAdapter extends BaseAdapter{
    private Context mContext;
    private List<String> mList = new ArrayList<>();

    public ImageAdapter(Context mContext, List<String> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public String getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    class ViewHolder{
        ImageView img;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_imgs,null);
            holder = new ViewHolder();
            holder.img = convertView.findViewById(R.id.item_img);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        Glide.with(mContext).load(getItem(position)).into(holder.img);
        return convertView;
    }

}
